<?php
require('lib/verify.php');
$_category = "warmath";
$_title = "Home";
require('lib/head.php');

$forum_id = $pun_user["id"];
$system_id = $system["system_id"];

$sql = "select * from wm_characters where character_forum_id = '$forum_id' and character_active='1'";
$result = $db->query($sql);

$character = $db->fetch_assoc($result);

$is_new = 1;

if($db->num_rows($result) > 0) {
  $is_new = 0;
}

if($is_new) {
?>

<?php
boxTop("Welcome to Warmath");
?>
Welcome to Warmath!
<?php
boxBot();
?>

<?php
boxTop("Register a Character: Join a Warmath-enabled Raid");
?>
Welcome.   As this appears to be your first time using Warmath, please <b><a href="register-character.php">Register a Character</a></b> in a Warmath system.
<?php
boxBot();
?>

<?php
    }
else {
  //announcement
 if($system["announcement"]!="") {

  boxTop($system["system_name"]);
?>
<?=$system["announcement"]?>
<b>We've resolved the load issues for now and are going to be able to continue the Beta.  Sorry for any panic!  <a href="http://forums.subcreation.net/viewtopic.php?id=3536">Details</a></b>
<?php
	 boxBot();
}
?>

<?php
    if(!$character["character_approved"]) {
?>

<?php
boxTop("Character Approval Pending");
?>
    An administrator for <?=$system["system_name"]?> has yet to approve your character.  Once this is done, you'll be able to access <?=$system["system_name"]?> Warmath.
<?php
    boxBot();
?>
<?php
    }
    else {
?>

<div id="leftpane" style="width: 72.4%; float: left;">
<?php
  boxTop($system["system_name"] . " Warmath: " . "Current DKP Standings");

$sort_phrase = $_GET["sort"];
$flip = $_GET["flip"];
if(!isset($sort_phrase)) {
$sort_phrase = "character_class";
}
if(!isset($flip)) {
$flip = 0;
}

?>
<table>
<tr>
<th width=35><a href="?sort=character_class<?php if($sort_phrase=="character_class") { echo "&flip=". (1-$flip);}?>">Class</a></th>
<th><a href="?sort=character_name<?php if($sort_phrase=="character_name") { echo "&flip=". (1-$flip);}?>">Character</a></th>
<th><a href="?sort=character_dkp_satout<?php if($sort_phrase=="character_dkp_satout") { echo "&flip=". (1-$flip);}?>">Satout</a></th>
<th><a href="?sort=character_dkp_earned<?php if($sort_phrase=="character_dkp_earned") { echo "&flip=". (1-$flip);}?>">Earned</a></th>
<th><a href="?sort=character_dkp_spent<?php if($sort_phrase=="character_dkp_spent") { echo "&flip=". (1-$flip);}?>">Spent</a></th>
<th><a href="?sort=character_dkp<?php if($sort_phrase=="character_dkp") { echo "&flip=". (1-$flip);}?>">DKP</a></th>
</tr>

<?php
if($sort_phrase=="character_dkp" ||
   $sort_phrase=="character_dkp_earned" ||
   $sort_phrase=="character_dkp_spent" ||
   $sort_phrase=="character_dkp_satout") {
$flip = 1 - $flip;
}

if($flip==1) {
$flip_phrase = "desc";
}
else {
$flip_phrase = "asc";
}

$sort_phrase = $db->escape($sort_phrase);

$sql = "select * from wm_characters where character_approved = 1 and character_system_id = $system_id order by $sort_phrase $flip_phrase, character_class asc, character_dkp desc, character_name asc";
$result = $db->query($sql);
while($chara = $db->fetch_assoc($result)) {
  if($chara["character_dkp_satout"]==0 and $chara["character_dkp_earned"] == 0) {
    continue;
  }
?>
<tr>
<td align="right"><?cclass($chara["character_class"])?></td>
<td><a href="character.php?id=<?=$chara["character_id"]?>"><?=$chara["character_name"]?></a></td>
<td align="right"><?=number_format($chara["character_dkp_satout"], 2)?></td>
<td align="right"><?=number_format($chara["character_dkp_earned"], 2)?></td>
<td align="right"><?=number_format($chara["character_dkp_spent"], 2)?></td>
<td align="right"><?=number_format($chara["character_dkp"], 2)?></td>
</tr>
<?php
}
?>
</table>
<?php
   boxBot();
?>
</div>
<div id="sidebar" style="float: right; width: 25%;">
<?php
boxTop("Warmath $warmath_version");
?>
This is <?=$warmath_codeclass?> <?=$warmath_version?>.<br />
&nbsp;&nbsp;&nbsp;<b><a href="http://forums.subcreation.net/viewforum.php?id=72">Warmath Beta Forums</a></b><br />
<?php
boxBot();
?>
<?php
    boxTop("Upcoming " . $system["system_name"] . " Raids");
?>
<?php
$ttime = time()-60*60*72;

$sql = "select *, wm_instances.* from wm_scheduled_raids left join wm_instances on wm_instances.instance_id = wm_scheduled_raids.scheduled_raid_instance where scheduled_raid_system_id='$system_id' and scheduled_raid_datetime > FROM_UNIXTIME($ttime) order by scheduled_raid_datetime desc limit 3";

$result = $db->query($sql);
 while($sraid = $db->fetch_assoc($result)) {
?>
<a href="signup.php?id=<?=$sraid["scheduled_raid_id"]?>"><b><?=date("D d M Y g:i a", strtotime($sraid["scheduled_raid_datetime"]))?></b></a><br />
   <?=$sraid["instance_name"]?>: 
<?php
$sql = "select *, wm_bosses.* from wm_scheduled_raid_bosses left join wm_bosses on wm_bosses.boss_id = wm_scheduled_raid_bosses.scheduled_raid_boss where scheduled_raid = '" . $sraid["scheduled_raid_id"] . "'";
$rez = $db->query($sql);
while($abo = $db->fetch_assoc($rez)) {
?>
<a href="boss.php?id=<?=$abo["boss_id"]?>"><?=$abo["boss_name_short"]?></a>
<?php
}
  ?> <br /><?php if($sraid["scheduled_raid_comments"]!="") { ?>
<i><?=$sraid["scheduled_raid_comments"]?></i><br />
<?php
   }?>
<br />
<?php
    }
?>
<?php
    boxBot();
?>
<?php
  boxTop("Latest Loot");
?>
<?php
$sql = "select *, wm_characters.*, wm_credits.*, wm_instances.*, wm_raids.*, wm_bosses.*, wm_item_values.* from wm_loots left join wm_characters on wm_characters.character_id = loot_character left join item_cache on wm_loots.loot_item = item_cache.item_id left join wm_credits on wm_credits.credit_id = wm_loots.loot_credit left join wm_bosses on wm_bosses.boss_id = wm_credits.credit_boss left join wm_raids on wm_raids.raid_id = wm_credits.credit_raid left join wm_instances on wm_instances.instance_id = wm_bosses.boss_instance left join wm_item_values on wm_item_values.item_id = wm_loots.loot_item where wm_credits.credit_system_id = $system_id  and wm_item_values.item_system_id=$system_id order by wm_credits.credit_date desc limit 6";
$result = $db->query($sql);

if($system["system_tier"]==4) {
$wish_text[1] = "Min";
$wish_text[2] = "Mod";
$wish_text[3] = "Max";
}
else {
$wish_text[1] = "Micro";
$wish_text[2] = "Min";
$wish_text[3] = "Mod";
$wish_text[4] = "Max";
}

while($loot = $db->fetch_assoc($result)) {

?>
<?cclass($loot["character_class"])?> <?php show_link(array("item_id" =>$loot["loot_item"]))?>
<a href="character.php?id=<?=$loot["loot_character"]?>"><?=$loot["character_name"]?></a> <?=$wish_text[$loot["loot_level"]]?> (<?=number_format($loot["loot_bid"],2)?> bid) (<?=number_format($loot["item_value"], 2)?> paid)<br />
<a href="credit.php?id=<?=$loot["credit_id"]?>"><?=$loot["boss_name"]?>, <?=date("g:i a", strtotime($loot["credit_date"]))?></a><br />
<a href="raid.php?id=<?=$loot["raid_id"]?>"><?=$loot["instance_name"]?>, <?=date("D d M Y", strtotime($loot["raid_date"]))?></a><br/>
<br />
<?php
}
?>

<?php
   boxBot();
?>
</div>
<br style="clear: both;" />



<?php
    }
}
?>
<?php
require('lib/foot.php');
?>

